<?php

namespace app\models;

use think\Model;

/**
 * Class ArrangingModel
 * @package app\models
 */
class ArrangingModel extends Model
{
    protected $table = 'edu_arranging';

    /**
     * @param $param
     *
     * @throws \think\exception\DbException
     *
     * @return array
     */
    public function getArrangingLists($param)
    {
        $page = isset($param['page']) ? (int) $param['page'] : 1;
        $listRows = isset($param['limit']) ? (int) $param['limit'] : 10;
        $where = [];
        if (isset($param['class_name']) && '' !== $param['class_name']) {
            $where['class_id'] = GradesModel::get(['class_name'=>$param['class_name']])['id'];
        }
        $listData = self::where($where)
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();
        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
                $item['status_text'] = (1 === $item['status']) ? '已上课' : '未上课';
                $item['class_name'] = GradesModel::get($item['class_id'])['class_name'];
                $item['class_room'] = ClassRoomModel::get($item['class_room'])['class_name'];
                $item['teacher'] = TeacherModel::get($item['teacher'])['teacher_name'];
            }
        }
        return $listData;
    }
}
